//import 'package:amap_base/amap_base.dart';

import 'dart:async';
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hotwork/HomePage.dart';
import 'package:flutter_hotwork/Myapplication.dart';
import 'package:flutter_hotwork/bean/BaseBean.dart';
import 'package:flutter_hotwork/homepage/BaseTitleBar.dart';
import 'package:flutter_hotwork/homepage/BaseViewBar.dart';
import 'package:flutter_hotwork/hotuserlist/HotUserData.dart';
import 'package:flutter_hotwork/utils/DioUtils.dart';
import 'package:fluttertoast/fluttertoast.dart';
// import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';

import '../LoadingDialog.dart';
import '../Toast.dart';

class changeactivity extends StatefulWidget {
  @override
  messagecenterState createState() => new messagecenterState();
}
int sex = 0;
class messagecenterState extends State<changeactivity> {

  @override
  void initState() {
    super.initState();
    DioUtils.createInstance();
  }
//手机号的控制器
  TextEditingController phoneController = TextEditingController();
  TextEditingController kaiguanController2 = TextEditingController();
  @override
  void dispose() {
//    _amapLocation.stopLocate();
    super.dispose();
  }
  void getCode() async {
    showDialog(
        context: context,
        builder: (context) {
          return new LoadingDialog();
        });
    // Navigator.pop(context);
    try {
      Response response;

        response = await DioUtils.dio.get(
            DioUtils.API_PREFIX + "/RegularData/sendVerificationCode?id="+MyApplication.changedidongfabean.id+"&&phone="+MyApplication.loginuserinfo.userInfo.phone);


      Map respMap = json.decode(response.data);
    basebean  bean  = basebean.fromJson(respMap);
      Navigator.pop(context);
      if (bean.code == 0) {
        setState(() {

        });
      } else {
         LocalToast.toast(context,msg: bean.message);
      }
    } catch (e) {
      Navigator.pop(context);
    }
  }


  void submit() async {
    showDialog(
        context: context,
        builder: (context) {
          return new LoadingDialog();
        });
    // Navigator.pop(context);
    try {
      Response response;

      response = await DioUtils.dio.get(
          DioUtils.API_PREFIX + "/RegularData/updateSmartHydrophobicInfo?id="+MyApplication.changedidongfabean.id+"&&code="+phoneController.text+"&&openClose="+sex.toString()+"&&phone="+MyApplication.loginuserinfo.userInfo.phone+"&&openingDegree="+kaiguanController2.text);
      Map respMap = json.decode(response.data);
      basebean  bean  = basebean.fromJson(respMap);
      Navigator.pop(context);
      if (bean.code == 0) {
        setState(() {

        });
      } else {
        LocalToast.toast(context,msg: bean.message);
      }
    } catch (e) {
      Navigator.pop(context);
      LocalToast.toast(context,msg: "信息错误");
    }
  }


  TabController _tabController;

  bool check = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:new BaseViewBar(
          childView:
          Column(
            children: [
              new BaseTitleBar(
                "电动阀控制",
                leftIcon: 'images/fanhui.png',
                rightIcon:  "",
                rightClick: () {
                  print("点击了右边干嘛啊。。。哦");
                },
                leftClick: () {
                  Navigator.pushAndRemoveUntil(
                    context,
                    new MaterialPageRoute(builder: (context) => new ReYongHuShuJuScreen()),
                        (route) => route == null,
                  );
                },
              )
              ,
            ],
          ),
          preferredSize: Size.fromHeight(58.0)

      ),
      body:
          Container(
          padding: EdgeInsets.only(left: 10),
          child:
          Column(
            children: [
              Row(
                children: <Widget>[
                  Text("用户名称："),
                  Container(
                    width: 10,
                  ),
                  Text(MyApplication.changedidongfabean.fullName),
                ],
              ),
              Container(height: 10,),
              Row(
                children: <Widget>[
                  Text("用户编号："),
                  Container(
                    width: 10,
                  ),
                  Text(MyApplication.changedidongfabean.userNumber),
                ],
              ),
              Row(
                children: <Widget>[
                  Text("电动阀类型："),
                  Container(
                    width: 10,
                  ),
                  Text("开："),
                  Radio(
                    value: 0,
                    groupValue: sex,
                    onChanged: (value) {
                      setState(() {
                        sex = value;
                      });
                    },
                  ),
                  SizedBox(width: 20),
                  Text("关："),
                  Radio(
                    value: 1,
                    groupValue: sex,
                    onChanged: (value) {
                      setState(() {
                        sex = value;
                      });
                    },
                  )
                ],
              ),
              Row(
                children: <Widget>[
                  Text("手机号码："),
                  Container(
                    width: 10,
                  ),
                  Text(MyApplication.loginuserinfo.userInfo.phone),
                ],
              ),
              Container(height: 10,),
              Row(
                children: <Widget>[
                  Text("开关度："),
                  Container(
                    width: 10,
                  ),
                  Container(
                    width: 100,
                    height: 20,
                    padding:  EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                    decoration: BoxDecoration(
                      border: new Border.all(color: Color(0xFF9E9E9E), width: 0.5), // 边色与边宽度
                      color: Colors.white, // 底色
                      //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                      borderRadius: BorderRadius.all(Radius.circular(15)),
                    ),
                    child:
                    TextField(

                      style: TextStyle(color: Colors.grey),
                      controller: kaiguanController2,
                      // controller: phoneController,
                      keyboardType: TextInputType.number,
                      decoration: InputDecoration(
                        contentPadding: EdgeInsets.all(10.0),

                        hintStyle: TextStyle(color: Colors.grey),
//                            helperText: '请输入注册的手机号',
                        border:InputBorder.none,
                      ),
                      autofocus: false,
                    ),

                  ),
                  Container(
                    width: 10,
                  ),

                ],
              ),
              Container(height: 10,),
              Row(
                children: <Widget>[
                  Text("验证码："),
                  Container(
                    width: 10,
                  ),
                  Container(
                    width: 100,
                    height: 20,
                    padding:  EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                    decoration: BoxDecoration(
                      border: new Border.all(color: Color(0xFF9E9E9E), width: 0.5), // 边色与边宽度
                      color: Colors.white, // 底色
                      //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                      borderRadius: BorderRadius.all(Radius.circular(15)),
                    ),
                    child:
                    TextField(

                      style: TextStyle(color: Colors.grey),
                      controller: phoneController,
                      // controller: phoneController,
                      keyboardType: TextInputType.number,
                      decoration: InputDecoration(
                        contentPadding: EdgeInsets.all(10.0),

                        hintStyle: TextStyle(color: Colors.grey),
//                            helperText: '请输入注册的手机号',
                        border:InputBorder.none,
                      ),
                      autofocus: false,
                    ),

                  ),
                  Container(
                    width: 10,
                  ),
                  InkWell(
                    onTap: (){
                      getCode();
                    },
                    child:
                  Container(
                    width: 90,
                    height: 20,
                    padding:  EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                    decoration: BoxDecoration(
                      border: new Border.all(color: Color(0xFF9E9E9E), width: 0.5), // 边色与边宽度
                      color: Colors.white, // 底色
                      //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                      borderRadius: BorderRadius.all(Radius.circular(5)),
                    ),
                    child:
                    Text("发送验证码"),
                  ),)

                ],
              ),
              Container(height: 50,),
              Row(
                mainAxisAlignment:MainAxisAlignment.center,
                children: [
                  InkWell(
                    onTap: (){
                      Navigator.pop(context);
                    },
                    child:
                  Container(
                    width: 90,
                    height: 20,
                    padding:  EdgeInsets.only(left: 30, right: 0, top:0, bottom: 0),
                    decoration: BoxDecoration(
                      color: Colors.grey, // 底色
                      //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                      borderRadius: BorderRadius.all(Radius.circular(5)),
                    ),
                    child:
                    Text("取消",style: TextStyle(color: Colors.white),),
                  ),
                  ),
                  Container(width: 50,),
                  InkWell(
                    onTap: (){
                      submit();
                    },
                    child:
                  Container(
                    width: 90,
                    height: 20,
                    padding:  EdgeInsets.only(left: 30, right: 0, top:0, bottom: 0),
                    decoration: BoxDecoration(
                      color: Colors.blue, // 底色
                      //        borderRadius: new BorderRadius.circular((20.0)), // 圆角度
                      borderRadius: BorderRadius.all(Radius.circular(5)),
                    ),
                    child:
                    Text("确定",style: TextStyle(color: Colors.white),),
                  ),
                  ),
                ],
              ),

            ],
          )


        ),
    );
  }


}






















